﻿using System;
using System.IO;
using SolutionSorter.Core;

namespace SolutionSorter.Console
{
    public class FileManager : IFileManager
    {
        public FileManager(IConfiguration config)
        {
            _config = config;
        }

        public string GetContent(string filePath)
        {
            return File.ReadAllText(filePath);
        }

        public void SaveContent(string filePath, string content)
        {
            if (_config.CreateNewSolutionFile)
            {
                int extensionIdx = filePath.LastIndexOf(".sln");
                filePath = filePath.Substring(0, filePath.Length - 4) + ".Sorted.sln";
            }
            File.WriteAllText(filePath, content);
        }

        IConfiguration _config;
    }
}
